﻿using Publicuse.Entity;
using Publicuse.Util;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Publicuse.Export
{
    public class OrganizationExport
    {
        /// <summary>
        /// 组织信息导出数据设置
        /// </summary>
        /// <param name="excelName"></param>
        /// <param name="fileName"></param>
        /// <param name="list"></param>
        /// <param name="msg"></param>
        /// <returns></returns>
        public static MemoryStream ExportData(
          string fileName,
          string excelName,
          List<Organization> list,
          out string msg
        )
        {
            msg = string.Empty;
            MemoryStream ms = ExcelUtil.GetExcelUtil.InitExportData(
              fileName,
              excelName,
              list,
              (row, cell, sheet1, TextSytle, srow, hssfworkbook) =>
              {
                  foreach (Organization item in list)
                  {
                      srow++;
                      row = sheet1.CreateRow(srow);

                      //名称
                      cell = row.CreateCell(0);
                      cell.CellStyle = TextSytle;
                      cell.SetCellValue(item.name);

                      //排序
                      cell = row.CreateCell(1);
                      cell.CellStyle = TextSytle;
                      cell.SetCellValue(item.order);

                      //状态
                      cell = row.CreateCell(2);
                      cell.CellStyle = TextSytle;
                      cell.SetCellValue(item.status == 1 ? "正常" : "停用");

                      //描述
                      cell = row.CreateCell(3);
                      cell.CellStyle = TextSytle;
                      cell.SetCellValue(item.Remark);

                      //创建时间
                      cell = row.CreateCell(4);
                      cell.CellStyle = TextSytle;
                      cell.SetCellValue(item.cTime.ToString("yyyy-MM-dd HH:mm:ss"));

                      //修改时间
                      cell = row.CreateCell(5);
                      cell.CellStyle = TextSytle;
                      cell.SetCellValue(item.uTime?.ToString("yyyy-MM-dd HH:mm:sss"));

                  }
              },
              out msg,
              2
            );
            return ms;
        }
    }
}
